// app.js
App({
    onLaunch() {
        wx.cloud.init({
            env: '7d4fbb8284d6c5f54831bd23348720bf', //这里替换成你自己的云开发环境id
            traceUser: true,
        })

        var that = this;
        // 获取openId
        wx.login({
            success(res) {
                if (res.code) {
                    //发起网络请求
                    wx.request({
                        url: that.globalData.baseUrl + 'api/wx/v1/getOpenId',
                        method: "POST",
                        data: {
                            code: res.code
                        },
                        success: function (suc) {
                            that.globalData.openid = suc.data.data.openId
                            var uinfo = wx.getStorageSync('userInfo');
                            if (uinfo) {
                                // that.globalData.userInfo = uinfo
                               that.getUserinfo()
                            }
                        }
                    })
                } else {
                    console.log('登录失败！' + res.errMsg)
                }
            }
        })
      
    },
    getUserinfo() {
        //获取用户的openid
        var that = this;
        // 如果之前缓存是登录状态则调取接口查询用户信息
        wx.request({
            url: that.globalData.baseUrl + 'api/wx/v1/getUserInfo',
            method: "POST",
            data: {
                openId: that.globalData.openid
            },
            success(suc) {
                that.globalData.userInfo = suc.data.data
            }
        })
    },
    globalData: {
        userInfo: null,
        openid: null,
        // URL:'http://127.0.0.1:8080/'
        baseUrl: 'http://127.0.0.1:8080/'
    }
})



// {
//   "selectedIconPath": "images/map_yes.png",
//   "iconPath": "images/map.png",
//   "pagePath": "pages/map/map",
//   "text": "地图"
// },
// 报价950 工期一周